﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Core;
using ZHDJ.Data.DataCaching;
using ZHDJ.Data.Models.Common;
using ZHDJ.Data.Models.Edu;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Portal
{
    public partial class PartyVideoDetail : PortalPage
    {
        #region 页面属性
        public string CourseID
        {
            get
            {
                return this.Request["id"];
            }
        }
        public string CourseTypeName
        {
            get; set;
        }
        public string CourseType
        {
            get; set;
        }

        public List<PartyEduCoursewareImage> Images { get; set; }

        /// <summary>
        /// 视频url
        /// </summary>
        public string FileUrl { get; set; }

        /// <summary>
        /// IsMp4
        /// </summary>
        public string IsMp4 { get; set; }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            var dt = GetVideo(CourseID);
            foreach (DataRow dr in dt.Rows)
            {
                litTitle.Text=this.lblTitle.Text = Convert.ToString(dr["fileName"]);
                this.lblTime.Text = Convert.ToDateTime(dr["endTime"]).ToString("yyyy-MM-dd HH:mm:ss");
                this.lbBranch.Text = "发布：" + SystemParameterCaching.Get(SystemParameterKey.WebArticleHostName);
                //if (!string.IsNullOrEmpty(Convert.ToString(dr["FileID"])))
                //{
                //    var fileName = UpFileBusiness.GetFileName(Convert.ToString(dr["FileID"]));
                //    var url = UpFileBusiness.GetFileUrl(Convert.ToString(dr["FileID"]));
                //    this.litFile.Text = string.Format("<a href='{0}' class='alink' title='下载'>{1}</a>", url, fileName);
                //    if (fileName.ToLower().EndsWith(".mp4") || fileName.ToLower().EndsWith(".flv"))
                //    {
                //        this.onlineVideo.Visible = true;
                //        FileUrl = url;
                //        IsMp4 = FileUrl.ToLower().EndsWith(".mp4") ? "1" : "0";
                //    }
                //}
                this.onlineVideo.Visible = true;
                IsMp4 = "1";
                FileUrl = SystemParameterCaching.Get(SystemParameterKey.UploadFileHost) + "/RecordFile/" + dr["fileDir"] + "/1_1.mp4";
                //FileUrl = "http://shtdj.shanhaitian.gov.cn/RecordFile/1111/1_1.mp4";
                //加载介绍图片
                //Images = DB.PartyEduCoursewareImages.Where(a => a.CoursewareID == CourseID).ToList();

                //展示点击数
                //this.lblClickCount.Text = Convert.ToString(dr["ClickCount"]);
                //var course = DB.PartyEduCoursewares.Find(CourseID);
                //course.ClickCount += 1;
                DB.SaveChanges();
                break;
            }

        }


        private DataTable GetVideo(string id) {
            string connectionstr = ConfigurationManager.ConnectionStrings["AppBoxContext2"].ConnectionString; ;
            string sql = @"select * from t_recordfileinfo where fileid='"+id+"'";

            return MySqlHelper.ExecuteDataset(connectionstr, sql, null).Tables[0];

        }
    }
}